package org.tuio4j;

import java.util.ArrayList;
import java.util.HashSet;

import org.tuio4j.message.TuioMessage;

/**
 * See license.txt for license information.
 * @author Uwe Laufs
 * @version 1.0
 */
public abstract class TuioProfile {
	public static String MESSAGETYPE_SET = "set";
	public static String MESSAGETYPE_FSEQ = "fseq";
	public static String MESSAGETYPE_ALIVE = "alive";
	public static String MESSAGETYPE_SOURCE = "source";
	
	private HashSet<Integer> aliveSessionIds = new HashSet<Integer>();
	private ArrayList<TUIOProfileListener> listeners = new ArrayList<TUIOProfileListener>();
	
	public void addAliveSessionId(int sessionId){
		this.aliveSessionIds.add(sessionId);
	}
	public void removeAliveSessionId(int sessionId){
		this.aliveSessionIds.remove(sessionId);
	}
	public boolean isAliveSessionId(int sessionId){
		return this.aliveSessionIds.contains(sessionId);
	}
	public Integer[] getAliveSessionIds(){
		Integer[] result = aliveSessionIds.toArray(new Integer[aliveSessionIds.size()]);
		return result;
	}
	/**
	 * Returns the address(es) a specific profile is listening to. A valid address for e.g. 2D cursor events is "/tuio/2Dobj". A profile implementation can also listen to more than one address.
	 * @return String[] containing tuio addresses, the profile is listening to.
	 */
	public abstract String[] getProfileAddress();
	public abstract void consumeMessage(TuioMessage m);
	
	public void addListener(TUIOProfileListener listener){
		if(!this.listeners.contains(listener)){
			this.listeners.add(listener);
		}
	}
	public TUIOProfileListener[] getListeners(){
		return this.listeners.toArray(new TUIOProfileListener[this.listeners.size()]);
	}
}
